package com.example.demo.pool;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author maxf
 * @version 1.0
 * @ClassName MysqlConfig
 * @Description
 * @date 2019/2/14 15:38
 */
@Configuration
@EnableScheduling
public class MysqlConfig {
    private MysqlPoolImpl mysqlPool;

    /**
     * 定时健康检查
     */
    @Scheduled(fixedRate = 60 * 1000)
    public void PoolScheduled() {
        mysqlPool.check();
    }

    @Bean
    public MysqlPool mysqlPool() {
        mysqlPool = new MysqlPoolImpl();
        mysqlPool.init();
        return mysqlPool;
    }
}
